package com.bdqn.BookManage.dao.impl;

import com.bdqn.BookManage.dao.OrderGoodsDao;
import com.bdqn.BookManage.po.OrderGoods;
import com.bdqn.BookManage.util.DBUtil;

import java.util.List;


/**
 * @author : CP
 * @version: 1.0
 * @program : BookManage
 * @description : 订单与商品信息关联接口实现类
 * @date : 2020-07-31 14:50
 **/
public class OrderGoodsDaoImpl implements OrderGoodsDao {
    @Override
    public boolean add(OrderGoods orderGoods) {
        String sql = "insert into ordergoods values(null,?,?,?,?,?,?,?)";
        Object [] obj = {orderGoods.getOrderId(),orderGoods.getGoodsId(),orderGoods.getGoodsNums(),
                orderGoods.getGoodsPrice(),orderGoods.getGoodsName(),orderGoods.getGoodsThums(),
                orderGoods.getCreateTime()};

        return DBUtil.connZsg(sql,obj);
    }

    @Override
    public OrderGoods queryByIo(String id) {
        OrderGoods orderGoods = null;
        String sql = "select * from `ordergoods` where orderId = ?";
        Object [] obj = {id};
        List<OrderGoods> orderList = (List<OrderGoods>) DBUtil.queryAll(sql, obj, OrderGoods.class);
        if(orderList.size() >0){
            orderGoods = orderList.get(0);
        }
        return orderGoods;
    }
}
